//
//  YSImagePlayView.m
//  Yaoyle
//
//  Created by ZhaoXudong on 14-10-21.
//  Copyright (c) 2014年 ZhaoXudong. All rights reserved.
//

#import "YSImagePlayView.h"

@implementation YSImagePlayView


-(void)play {
    frames = @[[UIImage imageNamed:@"loading_1"],
               [UIImage imageNamed:@"loading_2"],
               [UIImage imageNamed:@"loading_3"],
               [UIImage imageNamed:@"loading_4"],
               [UIImage imageNamed:@"loading_5"],
               [UIImage imageNamed:@"loading_6"],
               [UIImage imageNamed:@"loading_7"],
               [UIImage imageNamed:@"loading_8"],
               [UIImage imageNamed:@"loading_9"],
               [UIImage imageNamed:@"loading_10"],
               [UIImage imageNamed:@"loading_11"],
               [UIImage imageNamed:@"loading_12"],
               [UIImage imageNamed:@"loading_13"],
               [UIImage imageNamed:@"loading_14"],
               [UIImage imageNamed:@"loading_15"],
               [UIImage imageNamed:@"loading_16"]];
    
    timer=[NSTimer scheduledTimerWithTimeInterval:0.09
                                           target:self
                                         selector:@selector(timerHandler:)
                                         userInfo:nil
                                          repeats:YES];
    
    playIndex = 0;
}


-(void)timerHandler:(NSTimer *)timer{
	if (playIndex > [frames count]-1) {
		playIndex = 0;
	}
	
	self.image = [frames objectAtIndex:playIndex];
	playIndex++;
}

-(void)stop{
	[self pause];
	playIndex = 0;
}


-(void)pause{
    [timer invalidate];
    timer = nil;
}
@end
